<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" >
    <meta http-equiv="X-UA-Compatible" content="IE=11,IE=10,IE=9,IE=8" >
    <meta name="baidu-site-verification" content="dIcXMeY8Ya" />
    
    <title>maven | 即将拥有人鱼线丶</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" >
    <meta name="keywords" content="FutaoSmile, 前端, Web, 付韬, 个人博客" >
    <meta name="description" content="付韬FutaoSmile" >

    
    <link rel="alternative" href="/atom.xml" title="即将拥有人鱼线丶" type="application/atom+xml" >
    
    
    <link rel="shortcut icon" href="/coder957/coder957/favicon.ico" >
    
    <link rel="stylesheet" href="/coder957/css/style.css">
    <!--[if lt IE 9]>
    <script src="/coder957/js/html5.js"></script>
    <![endif]-->
    
<script>
    var _hmt = _hmt || [];
    (function() {
        var hm = document.createElement("script");
        hm.src = "//hm.baidu.com/hm.js?fd459238242776d173cdc64918fb32f2";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>


</head>

<body class="home">
    <!--[if lt IE 9]>
    <div class="browsehappy">
        当前网页 <strong>不支持</strong>
        你正在使用的浏览器. 为了正常的访问, 请 <a href="http://browsehappy.com/">升级你的浏览器</a>.
    </div>
    <![endif]-->

    <!-- 博客头部 -->
    <header class="header">
    <section class="container header-main">
        <div class="logo">
            <a href="/coder957/">
                <div class="cover">
                    <span class="name">即将拥有人鱼线丶</span>
                    <span class="description">FutaoSmile</span>
                </div>
            </a>
        </div>
        <div class="dropnav icon-paragraph-justify" id="JELON__btnDropNav"></div>
        <ul class="menu hidden" id="JELON__menu">
            
                <li rel="/coder957/2017/09/16/maven/index.html" class="item ">
                    <a href="/coder957/" title="首页" class="icon-home">&nbsp;首页</a>
                </li>
                
                <li rel="/coder957/2017/09/16/maven/index.html" class="item ">
                    <a href="/coder957/lab/" title="实验室" class="icon-lab">&nbsp;实验室</a>
                </li>
                
                <li rel="/coder957/2017/09/16/maven/index.html" class="item ">
                    <a href="/coder957/about/" title="关于" class="icon-about">&nbsp;关于</a>
                </li>
                
                <li rel="/coder957/2017/09/16/maven/index.html" class="item ">
                    <a href="/coder957/comment/" title="留言" class="icon-comment">&nbsp;留言</a>
                </li>
                
        </ul>
        <div class="profile clearfix">
            <div class="feeds fl">
                
                    
                        <p class="links">
                            
                                <a href="https://github.com/FutaoSmile" target="_blank">
                                    Github
                                </a>
                                |
                                    
                                        
                                <a href="http://www.jianshu.com/u/9e2e579df7dd" target="_blank">
                                    简书
                                </a>
                                
                                        
                        </p>
                        <p class="sns">
                            
                                <a href="http://weibo.com/u/2379076265?refer_flag=1001030001_&amp;nick=FutaoSmile%E4%B8%B6" class="sinaweibo" target="_blank"><b>■</b> 新浪微博</a>
                                
                                <a href="https://gitee.com/FutaoSmile" class="qqweibo" target="_blank"><b>■</b> 码云</a>
                                
                                    <!-- <a href="javascript: void(0);" class="wechat">
                        <b>■</b>
                        公众号
                        <span class="popover">
                            <img src="/coder957/img/wechat_mp.jpg" width="120" height="120" alt="我的微信订阅号">
                            <i class="arrow"></i>
                        </span>
                    </a> -->
                        </p>
                        
            </div>
            <div class="avatar fr">
                <img src="/coder957/img/head.png" alt="avatar" title="Jelon">
            </div>
        </div>
    </section>
</header>

    <!-- 博客正文 -->
    <div class="container body clearfix">
        <section class="content">
            <div class="content-main widget">
                <!-- 文章页 -->
<!-- 文章 -->
<article class="post article">
    <header class="text-center">
        <h3 class="post-title"><span>maven</span></h3>
    </header>
    <p class="post-meta text-center">
        FutaoSmile丶 发表于
            <time datetime="2017-09-16T15:04:57.000Z">2017-09-16</time>
    </p>
    <div class="post-content">
        <blockquote>
<p>Maven-Apache<br>项目构建工具，用来管理项目依赖</p>
</blockquote>
<a id="more"></a>
<p>Maven构建的项目非常小<br>jar包在仓库，而不在项目下面，Maven通过坐标去查找jar包（本地或中央仓库）。<br><strong>坐标：</strong>struts2-core-2.3.24.jar<br>Apache(公司名称)+Struts2(项目名称)+2.3.24(版本信息)</p>
<hr>
<h4 id="Maven两大核心"><a href="#Maven两大核心" class="headerlink" title="Maven两大核心"></a>Maven两大核心</h4><ol>
<li><strong>依赖管理</strong>：对jar包管理</li>
<li><strong>项目构建</strong>：项目在编码完成后，编译，打包，测试，部署–Maven通过命令来实现</li>
</ol>
<hr>
<h4 id="Maven安装"><a href="#Maven安装" class="headerlink" title="Maven安装"></a>Maven安装</h4><p>Maven安装前提：Maven程序由java开发，依赖jdk<br>java环境变量配置<br>maven环境变量配置<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">MAVEN_HOME                             bin的上一级</div><div class="line">PATH     ;%MAVEN_HOME%\bin;            bin目录</div><div class="line"></div><div class="line"></div><div class="line">cmd-&gt;</div><div class="line">java -version</div><div class="line">mvn -v</div></pre></td></tr></table></figure></p>
<hr>
<h4 id="Maven本地仓库配置"><a href="#Maven本地仓库配置" class="headerlink" title="Maven本地仓库配置"></a>Maven本地仓库配置</h4><p><img src="http://upload-images.jianshu.io/upload_images/1846623-17ab80d8be070233.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="仓库类型"><br>配置本地仓库：<br>\apache-maven-3.5.0\conf\settings.xml<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&lt;!-- localRepository</div><div class="line"> | The path to the local repository maven will use to store artifacts.</div><div class="line"> |</div><div class="line"> | Default: $&#123;user.home&#125;/.m2/repositoryrepository</div><div class="line">&lt;localRepository&gt;/path/to/local/repo&lt;/localRepository&gt;</div><div class="line">--&gt;</div></pre></td></tr></table></figure></p>
<hr>
<h4 id="标准目录结构"><a href="#标准目录结构" class="headerlink" title="标准目录结构"></a>标准目录结构</h4><p><img src="http://upload-images.jianshu.io/upload_images/1846623-02d26d4669a9c8fd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="标准目录结构"></p>
<hr>
<h4 id="Maven常用命令"><a href="#Maven常用命令" class="headerlink" title="Maven常用命令"></a>Maven常用命令</h4><p>java -clean，删除之前编译好的.class文件，重新编译一次<br><strong>mvn clean：</strong> 工作插件(可以在本地maven仓库找到对应的jar包)：maven-clean-plugin-清理项目下的target目录<br><strong>mvn compile：</strong> 工作插件：maven-compiler-plugin-编译，将项目中的.java文件编译成.class文件<br><strong>mvn test：</strong>单元测试，将项目根目录下面src/test/java目录下的单元测试类中的方法都会执行，类名要求：<strong>XxxxTest.java</strong><br><strong>mvn package：</strong>将项目打包到target目录下<br>web Project —-war包<br>java Project  —java包<br><strong>mvn install ：</strong>安装（打包）：将项目打包的文件放到本地仓库。解决本地多个项目共用一个jar包，该jar包发生更改后其他项目不需要改动，因为使用的是该jar包在maven本地仓库的坐标</p>
<h2 id="后面的动作会包含前面的动作"><a href="#后面的动作会包含前面的动作" class="headerlink" title="后面的动作会包含前面的动作"></a><strong>后面的动作会包含前面的动作</strong></h2><h4 id="Maven项目的生命周期"><a href="#Maven项目的生命周期" class="headerlink" title="Maven项目的生命周期"></a>Maven项目的生命周期</h4><p>在Maven中存在“三套”生命周期，每一套生命周期互相独立，互不影响。但是在同一套生命周期内，执行后面的命令，前面的命令会自动执行。<br><strong>CleanLifeCycle：清理生命周期</strong><br>clean<br><strong>defaultLifeCycle：默认生命周期</strong><br>      compile，test，package，install，deploy<br><strong>siteLiftCycle：站点生命周期</strong></p>
<h2 id="site"><a href="#site" class="headerlink" title="site"></a>site</h2><h4 id="坐标信息"><a href="#坐标信息" class="headerlink" title="坐标信息"></a>坐标信息</h4><p><strong>GroupId：</strong>公司域名倒序<br><strong>ArtifactId：</strong>项目名称<br><strong>Version：</strong>版本，SNAPSHOP：测试版本，RELEASES：发布版本</p>
<h2 id="Packaging：打包方式，jar：JAVA工程，war：web工程，pom：父工程"><a href="#Packaging：打包方式，jar：JAVA工程，war：web工程，pom：父工程" class="headerlink" title="Packaging：打包方式，jar：JAVA工程，war：web工程，pom：父工程"></a>Packaging：打包方式，jar：JAVA工程，war：web工程，pom：父工程</h2><h4 id="Maven依赖范围"><a href="#Maven依赖范围" class="headerlink" title="Maven依赖范围"></a>Maven依赖范围</h4><ol>
<li>compile:编译依赖范围(默认),对其三种都有效</li>
<li>test:测试依赖范围,只对测试classpath有效</li>
<li>runtime:运行依赖范围,只对测试和运行有效,编译主代码无效,例如JDBC</li>
<li>provided:已提供依赖范围,只对编译和测试有效,运行时无效,例如selvet-api</li>
<li>system:系统依赖范围.谨慎使用.例如本地的,maven仓库之外的类库文件</li>
<li>import(maven2.0.9以上):导入依赖范围,不会对其他三种有影响</li>
</ol>
<hr>
<p>pom.xml</p>
<ol>
<li>本项目的坐标信息</li>
<li>本项目jdk编译版本信息</li>
<li>本项目需要的插件/依赖信息</li>
</ol>
<h2 id="tips"><a href="#tips" class="headerlink" title="tips"></a>tips</h2><ol>
<li>子pom项目继承父pom项目，父项目必须在<code>&lt;dependencies&gt; &lt;/dependencies&gt;</code>外层再包裹一层<code>&lt;dependencyManagement&gt;    &lt;/dependencyManagement&gt;</code>，子项目才能继承到父项目的依赖的版本号，子项目才可以免写 <code>&lt;version&gt;&lt;/version&gt;</code></li>
</ol>
<ol>
<li>如果添加了<code>&lt;dependencyManagement&gt;    &lt;/dependencyManagement&gt;</code>,那么当前项目不会自动导包。</li>
</ol>

    </div>
    <p class="post-meta">
        <span class="post-cat">分类：
            <a class="cat-link" href="/coder957/categories/Java/">Java</a>|<a class="cat-link" href="/coder957/categories/Java/学习/">学习</a>
        </span>
        <span class="post-tags">
            标签：
            
    
        <a href="/coder957/tags/Maven/" title="Maven">Maven</a> / 
    
        <a href="/coder957/tags/热点文章/" title="热点文章">热点文章</a> / 
    
        <a href="/coder957/tags/博主推荐/" title="博主推荐">博主推荐</a>
    

        </span>
    </p>
</article>
<!-- 分享按钮 -->

  <div class="article-share clearfix text-center">
    <div class="share-area">
      <span class="share-txt">分享到：</span>
      <a href="javascript: window.open('http://service.weibo.com/share/share.php?url=' + encodeURIComponent(location.href) + '&title=' + document.title + '&language=zh_cn');" class="share-icon weibo"></a>
      <a href="javascript: alert('请复制链接到微信并发送');" class="share-icon wechat"></a>
      <a href="javascript: window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + encodeURIComponent(location.href) + '&title=' + document.title);" class="share-icon qqzone"></a>
      <a href="javascript: window.open('http://connect.qq.com/widget/shareqq/index.html?url=' + encodeURIComponent(location.href) + '&desc=Jelon个人博客&title=' + document.title + '&callback=' + encodeURIComponent(location.href));" class="share-icon qq"></a>
      <a href="javascript: window.open('http://shuo.douban.com/!service/share?href=' + encodeURIComponent(location.href) + '&name=' + document.title + '&text=' + document.title);" class="share-icon douban"></a>
    </div>
  </div>


    <!-- 上一篇/下一篇 -->

<div class="article-nav clearfix">
    
    <span class="prev fl">
        上一篇<br >
        <a href="/coder957/2017/09/19/慕课网Ajax学习笔记/">
            
                慕课网Ajax学习笔记
            
        </a>
    </span>
    

    
    <span class="next fr">
        下一篇<br >
        <a href="javascript: void(0);">没有下一篇了</a>
    </span>
    
</div>

        <!-- 文章评论 -->
        
  <script src="/coder957/js/comment.js"></script>
  <div id="comments" class="comment">
    <!--
    <div class="sign-bar">
      GitHub 已登录!
      <span class="sign-link">登出</span>
    </div>
    <section class="box">
      <div class="com-avatar"><img src="/img/jelon.jpg" alt="avatar"></div>
      <div class="com-text">
        <div class="main">
          <textarea class="text-area-edited show" placeholder="欢迎评论！"></textarea>
          <div class="text-area-preview"></div>
        </div>
        <div class="switch">
          <div class="switch-item on">编辑</div>
          <div class="switch-item">预览</div>
        </div>
        <div class="button">提交</div>
      </div>
    </section>
    <section class="tips">注：评论支持 markdown 语法！</section>
    <section class="list-wrap">
      <ul class="list">
        <li>
          <div class="user-avatar">
            <a href="/">
              <img src="/img/jelon.jpg" alt="user-avatar">
            </a>
          </div>
          <div class="user-comment">
            <div class="user-comment-header">
              <span class="post-name">张德龙</span>
              <span class="post-time">2017年12月12日</span>
              <span class="like liked">已赞</span>
              <span class="like-num">2</span>
            </div>
            <div class="user-comment-body">333333</div>
          </div>
        </li>
        <li>
          <div class="user-avatar">
            <a href="/">
              <img src="/img/jelon.jpg" alt="user-avatar">
            </a>
          </div>
          <div class="user-comment">
            <div class="user-comment-header">
              <span class="post-name">刘德华</span>
              <span class="post-time">2017年12月12日</span>
              <span class="like">点赞</span>
              <span class="like-num">2</span>
            </div>
            <div class="user-comment-body">vvvvv</div>
          </div>
        </li>
      </ul>
      <div class="page-nav">
        <a href="javascript: void(0);" class="item">1</a>
        <a href="javascript: void(0);" class="item">2</a>
        <a href="javascript: void(0);" class="item current">3</a>
      </div>
    </section>
    -->
  </div>
  <script>
  JELON.Comment({
    container: 'comments',
    label: 'maven' || '2017/09/16/maven/',
    owner: 'FutaoSmile',
    repo: 'blog_comments',
    clientId: '149ec394071cfd7f0f47',
    clientSecret: 'd1c988f53efa3f0f8651799f8212cc8e2cab24b9'
  });
  </script>


            </div>

        </section>
        <!-- 侧栏部分 -->
<aside class="sidebar">
    <section class="widget">
        <h3 class="widget-hd"><strong>文章分类</strong></h3>
        <!-- 文章分类 -->
<ul class="widget-bd">
    
    <li>
        <a href="/coder957/categories/后端/">后端</a>
        <span class="badge">(5)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/Java/">Java</a>
        <span class="badge">(8)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/Web技术/">Web技术</a>
        <span class="badge">(3)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/后端/Java/">Java</a>
        <span class="badge">(5)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/GIt/">GIt</a>
        <span class="badge">(1)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/Java/Spring/">Spring</a>
        <span class="badge">(3)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/Java/学习/">学习</a>
        <span class="badge">(5)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/Web技术/Java/">Java</a>
        <span class="badge">(1)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/Web技术/Kotlin/">Kotlin</a>
        <span class="badge">(1)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/GIt/Web技术/">Web技术</a>
        <span class="badge">(1)</span>
    </li>
    
    <li>
        <a href="/coder957/categories/学习/">学习</a>
        <span class="badge">(1)</span>
    </li>
    
</ul>
    </section>

    
    <section class="widget">
        <h3 class="widget-hd"><strong>热门标签</strong></h3>
        <!-- 文章标签 -->
<div class="widget-bd tag-wrap">
  
    <a class="tag-item" href="/coder957/tags/Java/" title="Java">Java (12)</a>
  
    <a class="tag-item" href="/coder957/tags/Spring/" title="Spring">Spring (9)</a>
  
    <a class="tag-item" href="/coder957/tags/kotlin/" title="kotlin">kotlin (7)</a>
  
    <a class="tag-item" href="/coder957/tags/Maven/" title="Maven">Maven (2)</a>
  
    <a class="tag-item" href="/coder957/tags/Hibernate/" title="Hibernate">Hibernate (2)</a>
  
    <a class="tag-item" href="/coder957/tags/kotlin-小知识/" title="kotlin 小知识">kotlin 小知识 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/Kotlin/" title="Kotlin">Kotlin (1)</a>
  
    <a class="tag-item" href="/coder957/tags/Json/" title="Json">Json (1)</a>
  
    <a class="tag-item" href="/coder957/tags/热点文章/" title="热点文章">热点文章 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/博主推荐/" title="博主推荐">博主推荐 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/转载/" title="转载">转载 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/资料/" title="资料">资料 (1)</a>
  
    <a class="tag-item" href="/coder957/tags/Ajax/" title="Ajax">Ajax (1)</a>
  
</div>
    </section>
    

    

    
    <!-- 友情链接 -->
    <section class="widget">
        <h3 class="widget-hd"><strong>友情链接</strong></h3>
        <!-- 文章分类 -->
<ul class="widget-bd">
    
        <li>
            <a href="http://lsc95.github.io/" target="_blank" title="椿哥的狗窝">椿哥的狗窝</a>
        </li>
    
        <li>
            <a href="http://futaosmile.oschina.io/documents/" target="_blank" title="donot click me">Document</a>
        </li>
    
        <li>
            <a href="" target="_blank" title="虚位以待">loading...</a>
        </li>
    
</ul>
    </section>
    
</aside>
<!-- / 侧栏部分 -->
    </div>

    <!-- 博客底部 -->
    <footer class="footer">
    &copy;
    
                2016-
                2017
                    

                        <a href="/coder957/">Loves You</a>
</footer>
<div class="back-to-top" id="JELON__backToTop" title="返回顶部">返回顶部</div>
    <!--博客js脚本 -->
    <!-- 这里放网站js脚本 -->
<script src="/coder957/js/main.js"></script>
</body>
</html>